<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Amaze UI Admin index Examples</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <script src="http://cdn.bootcss.com/echarts/3.3.2/echarts.min.js"></script>
    <link rel="stylesheet" th:href="@{/css/amazeui.min.css}" />
    <link rel="stylesheet" th:href="@{/css/amazeui.datatables.min.css}" />
    <link rel="stylesheet" th:href="@{/css/app.css}">
    <script th:src="@{/js/jquery.min.js}"></script>

    <script th:src="@{/js/jquery.md5.js}"></script>
    <base th:href="${#request.getContextPath()}+'/'">
<!--    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>-->

</head>

<body data-type="login">
    <script th:src="@{/js/theme.js}"></script>
    <div class="am-g tpl-g">
        <!-- 风格切换 -->
        <div class="tpl-skiner">
            <div class="tpl-skiner-toggle am-icon-cog">
            </div>
            <div class="tpl-skiner-content">
                <div class="tpl-skiner-content-title">
                    选择主题
                </div>
                <div class="tpl-skiner-content-bar">
                    <span class="skiner-color skiner-white" data-color="theme-white"></span>
                    <span class="skiner-color skiner-black" data-color="theme-black"></span>
                </div>
            </div>
        </div>
        <div class="tpl-login">
            <div class="tpl-login-content">
                <div class="tpl-login-logo">
                </div>
                <form class="am-form tpl-form-line-form" id="login">
                    <div class="am-form-group">
                        <input type="text" class="tpl-form-input" id="user-name" name="userName" placeholder="请输入账号">

                    </div>

                    <div class="am-form-group">
                        <input type="password" class="tpl-form-input" id="user-pass" name="userPass" placeholder="请输入密码">

                    </div>
                    <div class="am-form-group">

                        <button type="button" class="am-btn am-btn-primary  am-btn-block tpl-btn-bg-color-success  tpl-login-btn" onclick="login()">提交</button>

                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="http://cdn.bootcss.com/amazeui/2.7.2/js/amazeui.min.js"></script>
    <script th:src="@{/js/app.js}"></script>

    <script>

        function login(){
            var userName = $("#user-name").val();
            var password = $("#user-pass").val();
            password = infoEncrypt(userName,password)
            $.ajax({
                url: "admin/login",
                data: {"userName":userName,"password":password},
                type: 'post',
                dataType: 'json',
                success:function(response){
                    console.log(response)
                    if(response.result=='error'){
                        if(response.msg=='unknownAccount'){
                            alert('用户名错误');
                        }else if(response.msg=='incorrectCredentials'){
                            alert('密码错误')
                        }else if(response.msg=='服务器错误'){
                            alert('服务器错误')
                        }
                    }else{
                        window.location.href='index'
                    }
                }
            })
        }

        function infoEncrypt(userName, password) {
            var str1 = $.md5(password);
            var str2 = $.md5(str1 + userName);
            return str2;
        }

    </script>
</body>

</html>
